package com.qcby.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.qcby.Constants;
import com.qcby.model.MovieType;
import com.qcby.model.resp.RespEntity;
import com.qcby.query.MovieTypeQuery;
import com.qcby.service.MovieTypeService;
import com.qcby.util.Page;

@RestController
@RequestMapping("/movieType")
public class MovieTypeController {
    @Autowired
    private MovieTypeService movieTypeService;
    @RequestMapping("/selectAll")
    public RespEntity<Page<MovieType>> selectAll(@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        MovieTypeQuery mq = new MovieTypeQuery();
        mq.setPageNo(pageNo);
        mq.setPageSize(pageSize);
        Page<MovieType> movieTypes = movieTypeService.selectObjectByCondition(mq, "0");
        return RespEntity.successCustomize(Constants.FLAG_200, "查询成功！", movieTypes);
    }

    @RequestMapping("/insert")
    public RespEntity<String> add(@RequestParam String mtName) {
        MovieType mt = new MovieType();
        mt.setMtName(mtName);
        movieTypeService.insert(mt);
        return RespEntity.successNoData("添加电影类型成功！");
    }

    @RequestMapping("/update")
    public RespEntity<String> update(@RequestParam Integer mtId, @RequestParam String mtName) {
        MovieType mtNew = new MovieType();
        mtNew.setMtId(mtId);
        mtNew.setMtName(mtName);
        movieTypeService.updateByPrimaryKeySelective(mtNew);

        return RespEntity.successNoData("修改电影类型成功！");
    }

    @RequestMapping("/delete/{mtId}")
    public RespEntity<String> delete(@PathVariable Integer mtId) {
        movieTypeService.deleteByPrimaryKey(mtId);
        return RespEntity.successNoData("删除电影类型成功！");
    }

}